package cate.game.res.spicecall;

import cate.common.table.d.GDSpiceCall;
import cate.game.db.mongo.kv.KvMongo;
import cate.game.role.res.spicecall.SpiceCallLog;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.List;

public class SpiceCallSPO extends KvMongo {
    @NoteField(value = "日志")
    public List<SpiceCallLog> logs;

    @Override
    public String getKeyPrefix() {
        return KvMongo.KEY_SPICE_CALL_DATA;
    }

    @Override
    public void initialize() {
        if (logs == null) {
            logs = new ArrayList<>();
        }
    }

    public void addLog(int pos, String name, int rewardId) {
        SpiceCallLog log = new SpiceCallLog(pos, name, rewardId);
        final List<SpiceCallLog> list = logs;
        synchronized (list) {
            list.add(0, log);
            if (list.size() > GDSpiceCall.ZONE_LOG_MAX) {
                list.remove(list.size() - 1);
            }
        }
    }
}
